package server

import (
	"context"
	game_services "longmen/server/internal/rpc/games/services"
	pb "longmen/server/pkg/protobuf"
)

func (s *GameServer) Stages(ctx context.Context, req *pb.Empty) (*pb.StageResp, error) {
	return &pb.StageResp{
		Stages:    game_services.GetStages(),
		Countdown: game_services.RESET_COUNTDOWN,
	}, nil
}

func (s *GameServer) Signin(ctx context.Context, req *pb.SigninReq) (*pb.SigninResp, error) {
	chance, maxStage, currentStage, countdown, stages := game_services.Signin(int(req.UserId))

	return &pb.SigninResp{
		MaxStage:     int32(maxStage),
		CurrentStage: int32(currentStage),
		Chance:       int32(chance),
		Countdown:    int32(countdown),
		Stages:       stages,
	}, nil
}

func (s *GameServer) SigninStage(ctx context.Context, req *pb.SigninStageReq) (*pb.SigninStageResp, error) {
	ret, err := game_services.SignStage(int(req.UserId))
	return ret, err
}

func (s *GameServer) SigninHistory(ctx context.Context, req *pb.SigninHistoryReq) (*pb.SigninHistoryResp, error) {
	ret := game_services.SigninHistory(int(req.UserId))
	return &pb.SigninHistoryResp{
		SigninHistory: ret,
	}, nil
}
